package com.ruoyi.backend.controller.app;

import com.ruoyi.backend.domain.ShopBidding;
import com.ruoyi.backend.domain.Task;
import com.ruoyi.backend.service.IShopBiddingService;
import com.ruoyi.backend.service.ITaskService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺竞标Controller
 * 
 * @author wjr
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/app/backend/t_shop_bidding")
@Api(tags = "app-店铺竞标")
public class AppShopBiddingController extends BaseController
{
    @Autowired
    private IShopBiddingService shopBiddingService;
    @Autowired
    private ITaskService taskService;

    /**
     * 查询店铺竞标列表
     */
//    @PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:list')")
    @GetMapping("/list")
    @ApiOperation("查询店铺竞标列表")
    public TableDataInfo list(ShopBidding shopBidding)
    {
        startPage();
        List<ShopBidding> list = shopBiddingService.selectShopBiddingList(shopBidding);
        return getDataTable(list);
    }

    /**
     * 获取店铺竞标详细信息
     */
//    @PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取店铺竞标详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(shopBiddingService.selectShopBiddingById(id));
    }

    /**
     * 新增店铺竞标
     */
//    @PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:add')")
    @Log(title = "店铺竞标", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增店铺竞标")
    public AjaxResult add(@RequestBody ShopBidding shopBidding)
    {
        Integer taskId = shopBidding.getTaskId();
        if (taskId == null) {
            return AjaxResult.error("任务ID不能为空");
        }
        Task task = taskService.selectTaskById(taskId);
        if (task == null) {
            return AjaxResult.error("任务不存在");
        }
        //将竞标的相关参数填入竞标表中
        shopBidding.setTaskName(task.getTaskName());
        shopBidding.setTaskInfo(task.getTaskInfo());
        shopBidding.setCustomerId(task.getPublishId());
        shopBidding.setCustomerName(task.getPublishName());

        return toAjax(shopBiddingService.insertShopBidding(shopBidding));
    }

    /**
     * 修改店铺竞标
     */
//    @PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:edit')")
    @Log(title = "店铺竞标", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改店铺竞标")
    public AjaxResult edit(@RequestBody ShopBidding shopBidding)
    {
        return toAjax(shopBiddingService.updateShopBidding(shopBidding));
    }

    /**
     * 删除店铺竞标
     */
//    @PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:remove')")
    @Log(title = "店铺竞标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除店铺竞标")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shopBiddingService.deleteShopBiddingByIds(ids));
    }

    /**
     * 导出店铺竞标列表
     */
    /*@PreAuthorize("@ss.hasPermi('backend:t_shop_bidding:export')")
    @Log(title = "店铺竞标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopBidding shopBidding)
    {
        List<ShopBidding> list = shopBiddingService.selectShopBiddingList(shopBidding);
        ExcelUtil<ShopBidding> util = new ExcelUtil<ShopBidding>(ShopBidding.class);
        util.exportExcel(response, list, "店铺竞标数据");
    }*/

}
